<!DOCTYPE html>
<html lang=en>
<head>
    <!-- so meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="HandheldFriendly" content="True">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5" />
    <meta name="description" content="通过在IDEA中配置docker-maven-plugin插件，有效避免一些相同且繁琐的docker操作，交给IDEA一键打包，部署 配置CA证书使用此插件需要服务端开放2375端口，供IDEA连接。这也意味着不安全。安全小白的我一开始没有重视，刚配置完的晚上，就收到了服务器厂商的短信警告，果不其然，被黑客拉去挖矿了… 因此，首先花一分钟配置一下CA证书 依次执行一下命令： 12345678910">
<meta property="og:type" content="article">
<meta property="og:title" content="IDEA集成docker-maven-plugin配置CA安全证书">
<meta property="og:url" content="https://cheung0-bit.github.io/d0dd3ba40f1f/index.html">
<meta property="og:site_name" content="Bruce Zhang&#39;s Blogs">
<meta property="og:description" content="通过在IDEA中配置docker-maven-plugin插件，有效避免一些相同且繁琐的docker操作，交给IDEA一键打包，部署 配置CA证书使用此插件需要服务端开放2375端口，供IDEA连接。这也意味着不安全。安全小白的我一开始没有重视，刚配置完的晚上，就收到了服务器厂商的短信警告，果不其然，被黑客拉去挖矿了… 因此，首先花一分钟配置一下CA证书 依次执行一下命令： 12345678910">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/a0b7bcc64bd402ead57baf5f1b54a95a.png">
<meta property="og:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/83c477cb8699dbdc0fd80d646cd1616c.png">
<meta property="og:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/c8d24575a3476955a9577cc7b417fe04.png">
<meta property="og:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/6cab32ecaa8c520bc19792f56e8bff8c.png">
<meta property="og:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/b52234ee46682cb75a16a291581a41a6.png">
<meta property="og:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/45d8d1ae9b325165d62f19115739bdf8.png">
<meta property="og:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/ef88c464e5c68aae323dcd5e5b9519c8.png">
<meta property="og:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/da9aeb0cf3a43c5f6bd2b4ac2b2b8a77.png">
<meta property="article:published_time" content="2022-02-20T13:16:09.000Z">
<meta property="article:modified_time" content="2022-11-25T07:01:47.411Z">
<meta property="article:author" content="张林">
<meta property="article:tag" content="Docker">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/a0b7bcc64bd402ead57baf5f1b54a95a.png">
    
    
      
        
          <link rel="shortcut icon" href="/images/favicon.ico">
        
      
      
        
          <link rel="icon" type="image/png" href="/images/favicon-192x192.png" sizes="192x192">
        
      
      
        
          <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon.png">
        
      
    
    <!-- title -->
    <title>IDEA集成docker-maven-plugin配置CA安全证书</title>
    <!-- styles -->
    
<link rel="stylesheet" href="/css/style.css">

    <!-- persian styles -->
    
    <!-- rss -->
    
    
      <link rel="alternate" href="/atom.xml" title="Bruce Zhang&#39;s Blogs" type="application/atom+xml" />
    
	<!-- mathjax -->
	
<meta name="generator" content="Hexo 7.0.0"></head>

<body class="max-width mx-auto px3 ltr">
    
      <div id="header-post">
  <a id="menu-icon" href="#" aria-label="Menu"><i class="fas fa-bars fa-lg"></i></a>
  <a id="menu-icon-tablet" href="#" aria-label="Menu"><i class="fas fa-bars fa-lg"></i></a>
  <a id="top-icon-tablet" href="#" aria-label="Top" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');" style="display:none;"><i class="fas fa-chevron-up fa-lg"></i></a>
  <span id="menu">
    <span id="nav">
      <ul>
        <!--
       --><li><a href="/">Home</a></li><!--
     --><!--
       --><li><a href="/about/">About</a></li><!--
     --><!--
       --><li><a href="/archives/">Articles</a></li><!--
     --><!--
       --><li><a href="/categories/">Category</a></li><!--
     --><!--
       --><li><a href="/search/">Search</a></li><!--
     -->
      </ul>
    </span>
    <br/>
    <span id="actions">
      <ul>
        
        <li><a class="icon" aria-label="Previous post" href="/c36f3d1c0237/"><i class="fas fa-chevron-left" aria-hidden="true" onmouseover="$('#i-prev').toggle();" onmouseout="$('#i-prev').toggle();"></i></a></li>
        
        
        <li><a class="icon" aria-label="Next post" href="/2f4853fcdd44/"><i class="fas fa-chevron-right" aria-hidden="true" onmouseover="$('#i-next').toggle();" onmouseout="$('#i-next').toggle();"></i></a></li>
        
        <li><a class="icon" aria-label="Back to top" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up" aria-hidden="true" onmouseover="$('#i-top').toggle();" onmouseout="$('#i-top').toggle();"></i></a></li>
        <li><a class="icon" aria-label="Share post" href="#"><i class="fas fa-share-alt" aria-hidden="true" onmouseover="$('#i-share').toggle();" onmouseout="$('#i-share').toggle();" onclick="$('#share').toggle();return false;"></i></a></li>
      </ul>
      <span id="i-prev" class="info" style="display:none;">Previous post</span>
      <span id="i-next" class="info" style="display:none;">Next post</span>
      <span id="i-top" class="info" style="display:none;">Back to top</span>
      <span id="i-share" class="info" style="display:none;">Share post</span>
    </span>
    <br/>
    <div id="share" style="display: none">
      <ul>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.facebook.com/sharer.php?u=https://cheung0-bit.github.io/d0dd3ba40f1f/"><i class="fab fa-facebook " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://twitter.com/share?url=https://cheung0-bit.github.io/d0dd3ba40f1f/&text=IDEA集成docker-maven-plugin配置CA安全证书"><i class="fab fa-twitter " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.linkedin.com/shareArticle?url=https://cheung0-bit.github.io/d0dd3ba40f1f/&title=IDEA集成docker-maven-plugin配置CA安全证书"><i class="fab fa-linkedin " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://pinterest.com/pin/create/bookmarklet/?url=https://cheung0-bit.github.io/d0dd3ba40f1f/&is_video=false&description=IDEA集成docker-maven-plugin配置CA安全证书"><i class="fab fa-pinterest " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=IDEA集成docker-maven-plugin配置CA安全证书&body=Check out this article: https://cheung0-bit.github.io/d0dd3ba40f1f/"><i class="fas fa-envelope " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://getpocket.com/save?url=https://cheung0-bit.github.io/d0dd3ba40f1f/&title=IDEA集成docker-maven-plugin配置CA安全证书"><i class="fab fa-get-pocket " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://reddit.com/submit?url=https://cheung0-bit.github.io/d0dd3ba40f1f/&title=IDEA集成docker-maven-plugin配置CA安全证书"><i class="fab fa-reddit " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.stumbleupon.com/submit?url=https://cheung0-bit.github.io/d0dd3ba40f1f/&title=IDEA集成docker-maven-plugin配置CA安全证书"><i class="fab fa-stumbleupon " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://digg.com/submit?url=https://cheung0-bit.github.io/d0dd3ba40f1f/&title=IDEA集成docker-maven-plugin配置CA安全证书"><i class="fab fa-digg " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.tumblr.com/share/link?url=https://cheung0-bit.github.io/d0dd3ba40f1f/&name=IDEA集成docker-maven-plugin配置CA安全证书&description="><i class="fab fa-tumblr " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://news.ycombinator.com/submitlink?u=https://cheung0-bit.github.io/d0dd3ba40f1f/&t=IDEA集成docker-maven-plugin配置CA安全证书"><i class="fab fa-hacker-news " aria-hidden="true"></i></a></li>
</ul>

    </div>
    <div id="toc">
      <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%85%8D%E7%BD%AECA%E8%AF%81%E4%B9%A6"><span class="toc-number">1.</span> <span class="toc-text">配置CA证书</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#IDEA%E8%BF%9E%E6%8E%A5"><span class="toc-number">2.</span> <span class="toc-text">IDEA连接</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#maven%E4%B8%AD%E5%BC%95%E5%85%A5%E6%8F%92%E4%BB%B6"><span class="toc-number">3.</span> <span class="toc-text">maven中引入插件</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%86%99Dockerfile"><span class="toc-number">3.0.1.</span> <span class="toc-text">写Dockerfile</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%84%B6%E5%90%8E%EF%BC%8C%E5%A3%B0%E6%98%8E%E4%B8%80%E4%B8%AAdocker%E9%95%9C%E5%83%8F%E5%89%8D%E7%BC%80"><span class="toc-number">3.0.2.</span> <span class="toc-text">然后，声明一个docker镜像前缀</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#build-plugins-plugin%E5%BC%95%E5%85%A5docker-maven-plugin"><span class="toc-number">3.0.3.</span> <span class="toc-text">build-&gt;plugins-&gt;plugin引入docker-maven-plugin</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BA%AB%E5%8F%97%E6%88%90%E6%9E%9C"><span class="toc-number">4.</span> <span class="toc-text">享受成果</span></a></li></ol>
    </div>
  </span>
</div>

    
    <div class="content index py4">
        
        <article class="post" itemscope itemtype="http://schema.org/BlogPosting">
  <header>
    
    <h1 class="posttitle" itemprop="name headline">
        IDEA集成docker-maven-plugin配置CA安全证书
    </h1>



    <div class="meta">
      <span class="author" itemprop="author" itemscope itemtype="http://schema.org/Person">
        <span itemprop="name">张林</span>
      </span>
      
    <div class="postdate">
      
        <time datetime="2022-02-20T13:16:09.000Z" itemprop="datePublished">2022-02-20</time>
        
        (Updated: <time datetime="2022-11-25T07:01:47.411Z" itemprop="dateModified">2022-11-25</time>)
        
      
    </div>


      
    <div class="article-category">
        <i class="fas fa-archive"></i>
        <a class="category-link" href="/categories/%E5%BC%80%E5%8F%91%E5%AE%9E%E8%B7%B5/">开发实践</a>
    </div>


      
    <div class="article-tag">
        <i class="fas fa-tag"></i>
        <a class="tag-link-link" href="/tags/Docker/" rel="tag">Docker</a>
    </div>


    </div>
  </header>
  

  <div class="content" itemprop="articleBody">
    <p><strong>通过在IDEA中配置<code>docker-maven-plugin</code>插件，有效避免一些相同且繁琐的<code>docker</code>操作，交给IDEA一键打包，部署</strong></p>
<h2 id="配置CA证书"><a href="#配置CA证书" class="headerlink" title="配置CA证书"></a>配置CA证书</h2><p>使用此插件需要服务端开放2375端口，供<code>IDEA</code>连接。这也意味着不安全。安全小白的我一开始没有重视，刚配置完的晚上，就收到了服务器厂商的短信警告，果不其然，被黑客拉去挖矿了…</p>
<p>因此，首先花一分钟配置一下<code>CA</code>证书</p>
<p>依次执行一下命令：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 创建CA文件夹</span></span><br><span class="line"><span class="built_in">mkdir</span> -p /usr/local/ca</span><br><span class="line"><span class="comment"># 进入文件夹</span></span><br><span class="line"><span class="built_in">cd</span> /usr/local/ca</span><br><span class="line"><span class="comment">#  指定密码</span></span><br><span class="line">openssl genrsa -aes256 -out ca-key.pem 4096</span><br><span class="line"><span class="comment"># 录入相关信息</span></span><br><span class="line">openssl req -new -x509 -days 365 -key ca-key.pem -sha256 -out ca.pem</span><br><span class="line"><span class="comment"># 生成· server-key.pem</span></span><br><span class="line">openssl genrsa -out server-key.pem 4096</span><br><span class="line"><span class="comment"># 将HOST改为自己的IP或者域名</span></span><br><span class="line">openssl req -subj <span class="string">&quot;/CN=124.222.85.137&quot;</span> -sha256 -new -key server-key.pem -out server.csr</span><br><span class="line"><span class="comment"># 替换自己的IP 配置可访问的IP 0.0.0.0代表所有IP可以访问</span></span><br><span class="line"><span class="built_in">echo</span> subjectAltName = IP:192.168.1.195,IP:0.0.0.0 &gt;&gt; extfile.cnf</span><br><span class="line"><span class="comment"># 生成 extfile.cnf</span></span><br><span class="line"><span class="built_in">echo</span> extendedKeyUsage = serverAuth &gt;&gt; extfile.cnf</span><br><span class="line"><span class="comment"># 生成 ca-key</span></span><br><span class="line">openssl x509 -req -days 365 -sha256 -<span class="keyword">in</span> server.csr -CA ca.pem -CAkey ca-key.pem \-CAcreateserial -out server-cert.pem -extfile extfile.cnf</span><br><span class="line"><span class="comment"># 生成 key.pem</span></span><br><span class="line">openssl genrsa -out key.pem 4096</span><br><span class="line"><span class="comment"># 执行</span></span><br><span class="line">openssl req -subj <span class="string">&#x27;/CN=client&#x27;</span> -new -key key.pem -out client.csr</span><br><span class="line"><span class="built_in">echo</span> extendedKeyUsage = clientAuth &gt;&gt; extfile.cnf</span><br><span class="line"><span class="comment"># 生成 cert.pem</span></span><br><span class="line">openssl x509 -req -days 365 -sha256 -<span class="keyword">in</span> client.csr -CA ca.pem -CAkey ca-key.pem \-CAcreateserial -out cert.pem -extfile extfile.cnf</span><br><span class="line"><span class="comment"># 修改权限</span></span><br><span class="line"><span class="built_in">chmod</span> -v 0400 ca-key.pem key.pem server-key.pem</span><br><span class="line"><span class="built_in">chmod</span> -v 0444 ca.pem server-cert.pem cert.pem</span><br><span class="line"><span class="comment"># 复制到Docker目录下</span></span><br><span class="line"><span class="built_in">cp</span> server-*.pem  /etc/docker/</span><br><span class="line"><span class="built_in">cp</span> ca.pem /etc/docker/</span><br><span class="line"><span class="comment"># 修改docker配置文件</span></span><br><span class="line">vim  /lib/systemd/system/docker.service</span><br><span class="line"><span class="comment"># 将里面的ExecStart替换为</span></span><br><span class="line">ExecStart=/usr/bin/dockerd --tlsverify --tlscacert=/etc/docker/ca.pem --tlscert=/etc/docker/server-cert.pem --tlskey=/etc/docker/server-key.pem -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock</span><br><span class="line"><span class="comment"># 重新加载daemon</span></span><br><span class="line">systemctl daemon-reload</span><br><span class="line">systemctl restart docker</span><br><span class="line"><span class="comment"># 开放2375端口</span></span><br><span class="line">/sbin/iptables -I INPUT -p tcp --dport 2375  -j  ACCEPT</span><br><span class="line">iptables-save</span><br><span class="line"><span class="comment"># 重启</span></span><br><span class="line">service docker restart</span><br></pre></td></tr></table></figure>

<p>在服务器的控制台开放2375端口</p>
<p>将ca文件夹复制到自己的电脑上</p>
<p><img src="https://0-bit.oss-cn-beijing.aliyuncs.com/a0b7bcc64bd402ead57baf5f1b54a95a.png" alt="image-20220220194336759"></p>
<h2 id="IDEA连接"><a href="#IDEA连接" class="headerlink" title="IDEA连接"></a>IDEA连接</h2><p><img src="https://0-bit.oss-cn-beijing.aliyuncs.com/83c477cb8699dbdc0fd80d646cd1616c.png" alt="image-20220220194550218"></p>
<p><strong>在设置中连接IP，并放入CA文件夹</strong></p>
<p>在**服务(service)**窗口中可以看到，<code>Docker</code>服务已经存在。可以在里面方便地进行<code>Docker</code>的相关操作</p>
<p><img src="https://0-bit.oss-cn-beijing.aliyuncs.com/c8d24575a3476955a9577cc7b417fe04.png" alt="image-20220220194918722"></p>
<h2 id="maven中引入插件"><a href="#maven中引入插件" class="headerlink" title="maven中引入插件"></a>maven中引入插件</h2><h4 id="写Dockerfile"><a href="#写Dockerfile" class="headerlink" title="写Dockerfile"></a>写<code>Dockerfile</code></h4><p>自行选择一个地方写<code>Dockerfile</code></p>
<p><img src="https://0-bit.oss-cn-beijing.aliyuncs.com/6cab32ecaa8c520bc19792f56e8bff8c.png" alt="image-20220220195850578"></p>
<p>贴一份简单的针对<code>SpringBoot</code>项目的<code>Dockerfile</code>：</p>
<figure class="highlight dockerfile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">FROM</span> java:<span class="number">8</span></span><br><span class="line"><span class="keyword">VOLUME</span><span class="language-bash"> /tmp</span></span><br><span class="line"><span class="keyword">ADD</span><span class="language-bash"> metrichall-1.0.jar metrichall.jar</span></span><br><span class="line"><span class="keyword">EXPOSE</span> <span class="number">8080</span></span><br><span class="line"><span class="comment"># -Djava.security.egd=file:/dev/./urandom命令用于减少SpringBoot内嵌的Tomcat启动时间</span></span><br><span class="line"><span class="keyword">ENTRYPOINT</span><span class="language-bash"> [<span class="string">&quot;java&quot;</span>,<span class="string">&quot;-Djava.security.egd=file:/dev/./urandom&quot;</span>,<span class="string">&quot;-jar&quot;</span>,<span class="string">&quot;/metrichall.jar&quot;</span>]</span></span><br></pre></td></tr></table></figure>

<h4 id="然后，声明一个docker镜像前缀"><a href="#然后，声明一个docker镜像前缀" class="headerlink" title="然后，声明一个docker镜像前缀"></a>然后，声明一个docker镜像前缀</h4><p><img src="https://0-bit.oss-cn-beijing.aliyuncs.com/b52234ee46682cb75a16a291581a41a6.png" alt="image-20220220195141867"></p>
<h4 id="build-plugins-plugin引入docker-maven-plugin"><a href="#build-plugins-plugin引入docker-maven-plugin" class="headerlink" title="build-&gt;plugins-&gt;plugin引入docker-maven-plugin"></a><code>build</code>-&gt;<code>plugins</code>-&gt;<code>plugin</code>引入<code>docker-maven-plugin</code></h4><p><img src="https://0-bit.oss-cn-beijing.aliyuncs.com/45d8d1ae9b325165d62f19115739bdf8.png" alt="image-20220220195436191"></p>
<p>贴上代码：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"> <span class="tag">&lt;<span class="name">plugin</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.spotify<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>docker-maven-plugin<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">version</span>&gt;</span>1.0.0<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">configuration</span>&gt;</span></span><br><span class="line">         <span class="comment">&lt;!--远程Docker地址--&gt;</span></span><br><span class="line">         <span class="tag">&lt;<span class="name">dockerHost</span>&gt;</span>https://xxx.xxx.xxx.xxx:2375<span class="tag">&lt;/<span class="name">dockerHost</span>&gt;</span></span><br><span class="line">         <span class="comment">&lt;!--CA证书地址--&gt;</span></span><br><span class="line">         <span class="tag">&lt;<span class="name">dockerCertPath</span>&gt;</span>D:\ca<span class="tag">&lt;/<span class="name">dockerCertPath</span>&gt;</span></span><br><span class="line">         <span class="comment">&lt;!--镜像名称，前缀/项目名--&gt;</span></span><br><span class="line">         <span class="tag">&lt;<span class="name">imageName</span>&gt;</span>$&#123;docker.image.prefix&#125;/$&#123;project.artifactId&#125;<span class="tag">&lt;/<span class="name">imageName</span>&gt;</span></span><br><span class="line">         <span class="comment">&lt;!--Dockerfile的位置--&gt;</span></span><br><span class="line">         <span class="tag">&lt;<span class="name">dockerDirectory</span>&gt;</span>src/main/resources/docker<span class="tag">&lt;/<span class="name">dockerDirectory</span>&gt;</span></span><br><span class="line">         <span class="tag">&lt;<span class="name">resources</span>&gt;</span></span><br><span class="line">             <span class="tag">&lt;<span class="name">resource</span>&gt;</span></span><br><span class="line">                 <span class="tag">&lt;<span class="name">targetPath</span>&gt;</span>/<span class="tag">&lt;/<span class="name">targetPath</span>&gt;</span></span><br><span class="line">                 <span class="tag">&lt;<span class="name">directory</span>&gt;</span>$&#123;project.build.directory&#125;<span class="tag">&lt;/<span class="name">directory</span>&gt;</span></span><br><span class="line">                 <span class="tag">&lt;<span class="name">include</span>&gt;</span>$&#123;project.build.finalName&#125;.jar<span class="tag">&lt;/<span class="name">include</span>&gt;</span></span><br><span class="line">             <span class="tag">&lt;/<span class="name">resource</span>&gt;</span></span><br><span class="line">         <span class="tag">&lt;/<span class="name">resources</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;/<span class="name">configuration</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">plugin</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h2 id="享受成果"><a href="#享受成果" class="headerlink" title="享受成果"></a>享受成果</h2><p>通过maven插件打包(<code>mvn clean package</code>)</p>
<p><img src="https://0-bit.oss-cn-beijing.aliyuncs.com/ef88c464e5c68aae323dcd5e5b9519c8.png" alt="image-20220220200655050"></p>
<p>在docker插件中执行build镜像，或推送镜像到仓库中</p>
<p><img src="https://0-bit.oss-cn-beijing.aliyuncs.com/da9aeb0cf3a43c5f6bd2b4ac2b2b8a77.png" alt="image-20220220200755004"></p>
<p>后面，自行在docker服务窗口中进行生成容器，运行…</p>
<p><strong>这样，我们就可以在IDEA一键构建运行推送了！</strong></p>

  </div>
</article>


    <div class="blog-post-comments">
        <div id="utterances_thread">
            <noscript>Please enable JavaScript to view the comments.</noscript>
        </div>
    </div>


        
          <div id="footer-post-container">
  <div id="footer-post">

    <div id="nav-footer" style="display: none">
      <ul>
         
          <li><a href="/">Home</a></li>
         
          <li><a href="/about/">About</a></li>
         
          <li><a href="/archives/">Articles</a></li>
         
          <li><a href="/categories/">Category</a></li>
         
          <li><a href="/search/">Search</a></li>
        
      </ul>
    </div>

    <div id="toc-footer" style="display: none">
      <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%85%8D%E7%BD%AECA%E8%AF%81%E4%B9%A6"><span class="toc-number">1.</span> <span class="toc-text">配置CA证书</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#IDEA%E8%BF%9E%E6%8E%A5"><span class="toc-number">2.</span> <span class="toc-text">IDEA连接</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#maven%E4%B8%AD%E5%BC%95%E5%85%A5%E6%8F%92%E4%BB%B6"><span class="toc-number">3.</span> <span class="toc-text">maven中引入插件</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%86%99Dockerfile"><span class="toc-number">3.0.1.</span> <span class="toc-text">写Dockerfile</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%84%B6%E5%90%8E%EF%BC%8C%E5%A3%B0%E6%98%8E%E4%B8%80%E4%B8%AAdocker%E9%95%9C%E5%83%8F%E5%89%8D%E7%BC%80"><span class="toc-number">3.0.2.</span> <span class="toc-text">然后，声明一个docker镜像前缀</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#build-plugins-plugin%E5%BC%95%E5%85%A5docker-maven-plugin"><span class="toc-number">3.0.3.</span> <span class="toc-text">build-&gt;plugins-&gt;plugin引入docker-maven-plugin</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BA%AB%E5%8F%97%E6%88%90%E6%9E%9C"><span class="toc-number">4.</span> <span class="toc-text">享受成果</span></a></li></ol>
    </div>

    <div id="share-footer" style="display: none">
      <ul>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.facebook.com/sharer.php?u=https://cheung0-bit.github.io/d0dd3ba40f1f/"><i class="fab fa-facebook fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://twitter.com/share?url=https://cheung0-bit.github.io/d0dd3ba40f1f/&text=IDEA集成docker-maven-plugin配置CA安全证书"><i class="fab fa-twitter fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.linkedin.com/shareArticle?url=https://cheung0-bit.github.io/d0dd3ba40f1f/&title=IDEA集成docker-maven-plugin配置CA安全证书"><i class="fab fa-linkedin fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://pinterest.com/pin/create/bookmarklet/?url=https://cheung0-bit.github.io/d0dd3ba40f1f/&is_video=false&description=IDEA集成docker-maven-plugin配置CA安全证书"><i class="fab fa-pinterest fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=IDEA集成docker-maven-plugin配置CA安全证书&body=Check out this article: https://cheung0-bit.github.io/d0dd3ba40f1f/"><i class="fas fa-envelope fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://getpocket.com/save?url=https://cheung0-bit.github.io/d0dd3ba40f1f/&title=IDEA集成docker-maven-plugin配置CA安全证书"><i class="fab fa-get-pocket fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://reddit.com/submit?url=https://cheung0-bit.github.io/d0dd3ba40f1f/&title=IDEA集成docker-maven-plugin配置CA安全证书"><i class="fab fa-reddit fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.stumbleupon.com/submit?url=https://cheung0-bit.github.io/d0dd3ba40f1f/&title=IDEA集成docker-maven-plugin配置CA安全证书"><i class="fab fa-stumbleupon fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://digg.com/submit?url=https://cheung0-bit.github.io/d0dd3ba40f1f/&title=IDEA集成docker-maven-plugin配置CA安全证书"><i class="fab fa-digg fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.tumblr.com/share/link?url=https://cheung0-bit.github.io/d0dd3ba40f1f/&name=IDEA集成docker-maven-plugin配置CA安全证书&description="><i class="fab fa-tumblr fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://news.ycombinator.com/submitlink?u=https://cheung0-bit.github.io/d0dd3ba40f1f/&t=IDEA集成docker-maven-plugin配置CA安全证书"><i class="fab fa-hacker-news fa-lg" aria-hidden="true"></i></a></li>
</ul>

    </div>

    <div id="actions-footer">
        <a id="menu" class="icon" href="#" onclick="$('#nav-footer').toggle();return false;"><i class="fas fa-bars fa-lg" aria-hidden="true"></i> Menu</a>
        <a id="toc" class="icon" href="#" onclick="$('#toc-footer').toggle();return false;"><i class="fas fa-list fa-lg" aria-hidden="true"></i> TOC</a>
        <a id="share" class="icon" href="#" onclick="$('#share-footer').toggle();return false;"><i class="fas fa-share-alt fa-lg" aria-hidden="true"></i> Share</a>
        <a id="top" style="display:none" class="icon" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up fa-lg" aria-hidden="true"></i> Top</a>
    </div>

  </div>
</div>

        
        <footer id="footer">
  <div class="footer-left">
    Copyright &copy;
      
        
          2022-2024
            <a target="_blank" rel="noopener" href="https://beian.miit.gov.cn/">
              苏ICP备2022044873号
            </a>
  </div>
  <div class="footer-right">
    <nav>
      <ul>
        
          <!--
       -->
          <li><a href="/">
              Home
            </a></li>
          <!--
     -->
          
          <!--
       -->
          <li><a href="/about/">
              About
            </a></li>
          <!--
     -->
          
          <!--
       -->
          <li><a href="/archives/">
              Articles
            </a></li>
          <!--
     -->
          
          <!--
       -->
          <li><a href="/categories/">
              Category
            </a></li>
          <!--
     -->
          
          <!--
       -->
          <li><a href="/search/">
              Search
            </a></li>
          <!--
     -->
          
      </ul>
    </nav>
  </div>
</footer>
    </div>
    <!-- styles -->


 
  <link
    rel="preload"
    href="/lib/font-awesome/css/all.min.css"
    as="style"
    onload="this.onload=null;this.rel='stylesheet'"
  />
  <noscript
    ><link
      rel="stylesheet"
      href="/lib/font-awesome/css/all.min.css"
  /></noscript>



    <!-- jquery -->
 
  
<script src="/lib/jquery/jquery.min.js"></script>





<!-- clipboard -->

   
    
<script src="/lib/clipboard/clipboard.min.js"></script>

  
  <script type="text/javascript">
  $(function() {
    // copy-btn HTML
    var btn = "<span class=\"btn-copy tooltipped tooltipped-sw\" aria-label=\"Copy to clipboard!\">";
    btn += '<i class="far fa-clone"></i>';
    btn += '</span>'; 
    // mount it!
    $(".highlight table").before(btn);
    var clip = new ClipboardJS('.btn-copy', {
      text: function(trigger) {
        return Array.from(trigger.nextElementSibling.querySelectorAll('.code')).reduce((str,it)=>str+it.innerText+'\n','')
      }
    });
    clip.on('success', function(e) {
      e.trigger.setAttribute('aria-label', "Copied!");
      e.clearSelection();
    })
  })
  </script>


<script src="/js/main.js"></script>

<!-- search -->

<!-- Google Analytics -->

<!-- Baidu Analytics -->

  <script type="text/javascript">
        var _hmt = _hmt || [];
        (function() {
          var hm = document.createElement("script");
          hm.src = "https://hm.baidu.com/hm.js?4484a4a33014b59670c470a6e15a66db";
          var s = document.getElementsByTagName("script")[0];
          s.parentNode.insertBefore(hm, s);
        })();
        </script>

<!-- Cloudflare Analytics -->

<!-- Umami Analytics -->

<!-- Disqus Comments -->

<!-- utterances Comments -->

    <script type="text/javascript">
      var utterances_repo = 'Cheung0-bit/blog-package';
      var utterances_issue_term = 'title';
      var utterances_label = 'Comment';
      var utterances_theme = 'github-dark';

      (function(){
          var script = document.createElement('script');

          script.src = 'https://utteranc.es/client.js';
          script.setAttribute('repo', utterances_repo);
          script.setAttribute('issue-term', 'pathname');
          script.setAttribute('label', utterances_label);
          script.setAttribute('theme', utterances_theme);
          script.setAttribute('crossorigin', 'anonymous');
          script.async = true;
          (document.getElementById('utterances_thread')).appendChild(script);
      }());
  </script>

</body>
</html>
